﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using App.Common;
using QxFramework.Core;
using System;
public class MapEditorGround : MapEditorBase
{
    private SpriteRenderer Print;
    public bool IsPlayerIn;
    public override void Awake()
    {
        base.Awake();
        Print = transform.Find("Print").GetComponent<SpriteRenderer>();
    }
    public override void OnEnable()
    {
        base.OnEnable();
        UpdatePrintColor();
        Alph = Print.color.a;
        Print.sprite = ResourceManager.Instance.Load<Sprite>("Texture/SceneObj/FloorPrint");

        int TempID = int.Parse(gameObject.name.Split('(')[1].Split(')')[0]);
        int RamID = 0;
        if (TempID%2 == 0)
        {
            RamID = 1;
        }
        else if (TempID % 3 == 0)
        {
            RamID = UnityEngine.Random.Range(1, 4);
        }
        else if (TempID % 5 == 0)
        {
            RamID = UnityEngine.Random.Range(1, 5);
        }
        else if (TempID % 11 == 0)
        {
            RamID = UnityEngine.Random.Range(3, 9);
        }
        else
        {
            RamID = UnityEngine.Random.Range(1, 3);
        }
        GetComponent<SpriteRenderer>().sprite = ResourceManager.Instance.Load<Sprite>("Texture/SceneObj/Floor/Floor (" + RamID + ")");
        GetComponent<SpriteRenderer>().sortingOrder = -100;
        Print.sortingOrder = -95;
    }
    public override void LateUpdate()
    {
        if (!GameMgr.Get<ISceneMonoManager>().GetAllSceneMono()._sceneMonoDatas.ContainsKey(gameObject.name))
        {
            return;
        }
        base.Update();
        //CheckPlayerIsIn();
        UpdatePrintColor();
    }
    private void UpdatePrintColor()
    {
        var printColor = Data.Instance.PrintColor;
        switch (attr)
        {
            case MonoAttribute.None:
                Print.color = new Color(0,0,0,0);
                break;
            case MonoAttribute.Fire:
                Print.color = Data.Instance.PrintColor[0];
                ColorAnim();
                break;
            case MonoAttribute.Ice:
                Print.color = Data.Instance.PrintColor[1];
                ColorAnim();
                break;
            case MonoAttribute.Shine:
                Print.color = Data.Instance.PrintColor[2];
                ColorAnim();
                break;
            case MonoAttribute.Dark:
                Print.color = Data.Instance.PrintColor[3];
                ColorAnim();
                break;
            case MonoAttribute.Steam:
                Print.color = Data.Instance.PrintColor[4];
                ColorAnim();
                break;
            case MonoAttribute.Electric:
                Print.color = Data.Instance.PrintColor[5];
                ColorAnim();
                break;
            case MonoAttribute.Oil:
                Print.color = Data.Instance.PrintColor[6];
                ColorAnim();
                break;
            default:
                break;
        }
    }

    float Alph;
    float AlphPlus;
    private void ColorAnim()
    {
        if (IsPlayerIn)
        {
            if (Alph > 1)
            {
                AlphPlus = -0.025f;
            }
            if (Alph < 0.6f)
            {
                AlphPlus = 0.025f;
            }
            Alph += AlphPlus;
        }
        else
        {
            Alph -= 0.025f;
            if (Alph < 0.5f)
            {
                Alph = 0.5f;
            }
        }
        Print.color = new Color(Print.color.r, Print.color.g, Print.color.b, Alph);
    }
    public override void OnDrawGizmos()
    {
        switch (attr)
        {
            case MonoAttribute.None:
                Gizmos.color = new Color(1, 1, 1, 1);
                break;
            case MonoAttribute.Fire:
                Gizmos.color = Data.Instance.PrintColor[0];
                break;
            case MonoAttribute.Ice:
                Gizmos.color = Data.Instance.PrintColor[1];
                break;
            case MonoAttribute.Shine:
                Gizmos.color = Data.Instance.PrintColor[2];
                break;
            case MonoAttribute.Dark:
                Gizmos.color = Data.Instance.PrintColor[3];
                break;
            case MonoAttribute.Steam:
                Gizmos.color = Data.Instance.PrintColor[4];
                break;
            case MonoAttribute.Electric:
                Gizmos.color = Data.Instance.PrintColor[5];
                break;
            case MonoAttribute.Oil:
                Gizmos.color = Data.Instance.PrintColor[6];
                break;
            default:
                break;
        }
        base.OnDrawGizmos();
    }
}
